﻿<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html"/>

  <xsl:param name="details">true</xsl:param>
  <xsl:param name="pageTitle">Movie Collection</xsl:param>
  <xsl:param name="thumbnails">false</xsl:param>

  <xsl:variable name="nrOfActors">3</xsl:variable>

  <xsl:include href="shared_templates.xsl"/>

  <!-- Auxiliary method to display a limited set of actors for the movie. -->
  <xsl:template name="formatActors">
    <xsl:for-each select="actors/actor[position() &lt;= $nrOfActors]">
      <xsl:apply-templates select="node()"/>
      <br/>
    </xsl:for-each>
  </xsl:template>

  <!-- the main template -->
  <xsl:template match="/">
    <HTML>
      <HEAD>
        <LINK REL="StyleSheet" TYPE="text/css" HREF="exportindex_item_aqua2.css"></LINK>
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <TITLE>Movie List</TITLE>
      </HEAD>
      <BODY>
        <center>
          <table border="0" cellspacing="0" cellpadding="0" width="100%">
            <tr>
              <td class="ptitle">
                <xsl:if test="$pageTitle!=''">
                  <xsl:value-of select="$pageTitle"/>
                </xsl:if>
              </td>
            </tr>
          </table>
          <xsl:apply-templates select="movies/navigation"/>
          <br/>
          <br/>
          <table cellspacing="1">
            <xsl:apply-templates/>
          </table>
        </center>
      </BODY>
    </HTML>
  </xsl:template>

  <xsl:template match="movieInfo">
    <table border="0" cellspacing="3" cellpadding="0" width="87%" align="center" class="value">
      <tr>
        <td class="line">
          <table border="0" cellspacing="0" cellpadding="0" width="100%">
            <tr align="centre">
              <xsl:if test="picture!=''">
                <td width="1" class="line">
                  <xsl:choose>
                    <xsl:when test="$details='true'">
                      <a href="details/{id}.html">
                        <img src="images/{id}t.jpg" border="0" width="92"/>
                      </a>
                    </xsl:when>
                    <xsl:otherwise>
                      <a href="images/{id}.jpg">
                        <img src="images/{id}t.jpg" border="0" width="92"/>
                      </a>
                    </xsl:otherwise>
                  </xsl:choose>
                </td>
              </xsl:if>
              <td width="100%" class="line">
                <table border="0" cellspacing="2" cellpadding="0" width="100%">
                  <tr cellspacing="0">
                    <td class="maintitle" width="100%">
                      <xsl:value-of select="title"/>
                      <xsl:if test="year!=''">
                        <xsl:text> (</xsl:text><xsl:value-of select="year"/>)
                      </xsl:if>
                    </td>
                    <xsl:if test="mpaaRating!=''">
                      <td align="right" class="maintitle" valign="centre">
                        <xsl:choose>
                          <xsl:when test="starts-with(mpaaRating, 'G')">
                            <img src="images/MPAA/G.gif" width="30" height="24"/>
                          </xsl:when>
                          <xsl:when test="starts-with(mpaaRating, 'PG-13')">
                            <img src="images/MPAA/PG-13.gif" width="59" height="24"/>
                          </xsl:when>
                          <xsl:when test="contains(mpaaRating, 'PG')">
                            <img src="images/MPAA/PG.gif" width="40" height="24"/>
                          </xsl:when>
                          <xsl:when test="contains(mpaaRating, 'R')">
                            <img src="images/MPAA/R.gif" width="26" height="24"/>
                          </xsl:when>
                          <xsl:when test="contains(mpaaRating, 'NC-17')">
                            <img src="images/MPAA/NC-17.gif" width="53" height="24"/>
                          </xsl:when>
                        </xsl:choose>
                      </td>
                    </xsl:if>
                  </tr>
                </table>

                <table border="0" cellspacing="0" cellpadding="0" width="100%">
                  <tr>
                    <td class="tag" cellspacing="2" height="17" width="100%">
                      <xsl:value-of select="tagline"/>
                    </td>
                  </tr>
                </table>

                <table border="0" cellspacing="2" cellpadding="0" width="100%">
                  <tr  valign="middle">
                    <td class="label" width="9%" nowrap="1" height="17">
                      <xsl:value-of select="/movies/metadata/field[@name='runtime']/@label"/>
                    </td>

                    <td class="value" width="15%" height="17">
                      <xsl:value-of select="runtime"/>
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="/movies/metadata/field[@name='runtimeUnit']/@label"/>
                    </td>

                    <td class="label" width="9%" nowrap="1" height="17" align="right" valign="middle">
                      <xsl:value-of select="/movies/metadata/field[@name='genres']/@label"/>
                    </td>

                    <td class="value" height="17">
                      <xsl:for-each select="genres/genre">
                        <xsl:value-of select="node()"/>
                        <xsl:if test="position()!=last()">
                          <xsl:text>; </xsl:text>
                        </xsl:if>
                      </xsl:for-each>
                    </td>

                    <td class="value" align="right" width="18%">
                      <xsl:if test="$details='true'">
                        <a padding="3" href="details/{id}.html">
                          <span>
                            <span>
                              <xsl:value-of select="/movies/metadata/field[@name='details']/@label"/>
                            </span>
                          </span>
                        </a>
                      </xsl:if>
                    </td>

                  </tr>

                  <tr valign="middle">

                    <td class="value" colspan="2">
                      <table border="0" cellspacing="0" cellpadding="0" width="100%">
                        <td class="actor" align="centre">
                          <xsl:if test="actors!=''">
                            <xsl:call-template name="formatActors"/>
                          </xsl:if>
                        </td>
                      </table>
                    </td>

                    <td class="value" colspan="3">
                      <xsl:call-template name="break">
                        <xsl:with-param name="text" select="description"/>
                      </xsl:call-template>
                    </td>
                  </tr>
                </table>


                <table border="0" cellspacing="1" cellpadding="0" width="100%">

                  <xsl:if test="imdbRating!=''">
                    <td class="value" nowrap="1" width="10%">
                      <xsl:value-of select="/movies/metadata/field[@name='imdbRating']/@label"/>
                    </td>
                    <td class="stars" width="25%">
                      <xsl:choose>
                        <xsl:when test="contains(imdbRating,' ')">
                          <xsl:call-template name="starIMDB">
                            <xsl:with-param name="numIMDB" select="substring-before(imdbRating,' ')"/>
                          </xsl:call-template>
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:call-template name="starIMDB">
                            <xsl:with-param name="numIMDB" select="imdbRating"/>
                          </xsl:call-template>
                        </xsl:otherwise>
                      </xsl:choose>
                    </td>
                    <td class="value">
                      <xsl:value-of select="imdbRating"/>
                    </td>
                  </xsl:if>

                </table>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    <br>
    </br>
  </xsl:template>


  <xsl:template match="navigation">
    <xsl:if test="count(pagelink) > 1">
      <br/>
      <xsl:for-each select="pagelink">
        <xsl:choose>
          <xsl:when test="@url!=''">
            <a href="{@url}" class="link">
              <span>
                <xsl:value-of select="@pagenum"/>
              </span>
            </a>
          </xsl:when>
          <xsl:otherwise>
            <span>
              <xsl:value-of select="@pagenum"/>
            </span>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:if test="position()!=last()">
          <span>
            <xsl:text> - </xsl:text>
          </span>
        </xsl:if>
      </xsl:for-each>
      <br/>
      <xsl:choose>
        <xsl:when test="firstlink/@url!=''">
          <a href="{firstlink/@url}" class="link">
            <span>
              <xsl:value-of select="/movies/metadata/field[@name='first']/@label"/>
            </span>
          </a>|
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="/movies/metadata/field[@name='first']/@label"/>|
        </xsl:otherwise>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="prevlink/@url!=''">
          <a href="{prevlink/@url}" class="link">
            <span>
              <xsl:value-of select="/movies/metadata/field[@name='prev']/@label"/>
            </span>
          </a>|
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="/movies/metadata/field[@name='prev']/@label"/>|
        </xsl:otherwise>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="nextlink/@url!=''">
          <a href="{nextlink/@url}" class="link">
            <span>
              <xsl:value-of select="/movies/metadata/field[@name='next']/@label"/>
            </span>
          </a>|
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="/movies/metadata/field[@name='next']/@label"/>|
        </xsl:otherwise>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="lastlink/@url!=''">
          <a href="{lastlink/@url}" class="link">
            <span>
              <xsl:value-of select="/movies/metadata/field[@name='last']/@label"/>
            </span>
          </a>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="/movies/metadata/field[@name='last']/@label"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>

